<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html><head><meta name="qrichtext" content="1" /><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><style type="text/css">
p, li { white-space: pre-wrap; }
</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:9pt; font-weight:400; font-style:normal;">
<table border="0" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px;" cellspacing="2" cellpadding="0">
<tr>
<td></td>
<td>
<table border="0" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px;" cellspacing="2" cellpadding="0">
<tr>
<td>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><a href="http://excelvba.ru/code/ShowText"><span style=" text-decoration: underline; color:#0000ff;">Просмотр длинной текстовой строки (сохранение текста в файл)</span></a> </p>
<ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"><li style=" font-size:8.25pt;" style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><a href="http://excelvba.ru/taxonomy/term/14"><span style=" text-decoration: underline; color:#0000ff;">Макросы VBA Excel</span></a></li>
<li style=" font-size:8.25pt;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><a href="http://excelvba.ru/code/strings"><span style=" text-decoration: underline; color:#0000ff;">Текстовые строки</span></a></li>
<li style=" font-size:8.25pt;" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><a href="http://excelvba.ru/code/text_files"><span style=" text-decoration: underline; color:#0000ff;">Текстовые файлы</span></a> </li></ul></td></tr></table>
<p style=" margin-top:18px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8.25pt; font-weight:600;">Данный макрос предназначен для облегчения анализа длинных текстовых строк.</span></p>
<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8.25pt;">К примеру, в вашем макросе формируется длинная текстовая строка (вы сцепили значения диапазона ячеек, или загрузили текст веб-страницы в текстовую переменную)</span></p>
<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8.25pt;">Чтобы проанализировать текст на этапе отладки программы, вам необходимо изучить структуру этого текста, - а это удобнее делать в текстовом редакторе<br />(например, в </span><span style=" font-size:8.25pt; font-weight:600; font-style:italic;">Блокноте</span><span style=" font-size:8.25pt;">, хотя лично я использую только </span><span style=" font-size:8.25pt; font-weight:600; font-style:italic;">Notepad++</span><span style=" font-size:8.25pt;">, поскольку он в тысячу раз удобнее Блокнота)</span></p>
<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8.25pt;">В этом вам поможет макрос </span><span style=" font-size:8.25pt; font-weight:600;">ShowText</span><span style=" font-size:8.25pt;">:</span></p>
<p style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; font-size:8.25pt; color:#000080;">Sub</span><span style=" font-family:'monospace'; font-size:8.25pt;"> ПримерИспользования_ShowText()</span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; font-size:8.25pt;">    </span><span style=" font-family:'monospace'; font-size:8.25pt; color:#008000;">' исходный текст любой длины в переменной txt</span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; font-size:8.25pt;">    txt = </span><span style=" font-family:'monospace'; font-size:8.25pt; color:#800000;">&quot;Некая текстовая строка, которую нам надо сохранить в файл&quot;</span><span style=" font-family:'monospace'; font-size:8.25pt;"> &amp; vbNewLine &amp; _</span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; font-size:8.25pt;">           </span><span style=" font-family:'monospace'; font-size:8.25pt; color:#800000;">&quot;Поскольку текстовая строка весьма длинная, просматривать её в MSGBOX не удобно&quot;</span><span style=" font-family:'monospace'; font-size:8.25pt;"> &amp; vbNewLine &amp; _</span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; font-size:8.25pt;">           </span><span style=" font-family:'monospace'; font-size:8.25pt; color:#800000;">&quot;Потому мы её просмотрим в Блокноте, предварительно создав временный текстовый файл&quot;</span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; font-size:8.25pt;"> </span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; font-size:8.25pt;">    </span><span style=" font-family:'monospace'; font-size:8.25pt; color:#008000;">' сохраняем строку в файл, и открываем файл в Блокноте</span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; font-size:8.25pt;">    ShowText txt</span></p>
<p style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; font-size:8.25pt; color:#000080;">End</span><span style=" font-family:'monospace'; font-size:8.25pt;"> </span><span style=" font-family:'monospace'; font-size:8.25pt; color:#000080;">Sub</span></p>
<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8.25pt;"> </span></p>
<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8.25pt;">Код макроса </span><span style=" font-size:8.25pt; font-weight:600;">ShowText</span><span style=" font-size:8.25pt;">:</span></p>
<p style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; font-size:8.25pt; color:#000080;">Sub</span><span style=" font-family:'monospace'; font-size:8.25pt;"> ShowText(</span><span style=" font-family:'monospace'; font-size:8.25pt; color:#000080;">ByVal</span><span style=" font-family:'monospace'; font-size:8.25pt;"> txt </span><span style=" font-family:'monospace'; font-size:8.25pt; color:#000080;">As</span><span style=" font-family:'monospace'; font-size:8.25pt;"> </span><span style=" font-family:'monospace'; font-size:8.25pt; color:#000080;">String</span><span style=" font-family:'monospace'; font-size:8.25pt;">, </span><span style=" font-family:'monospace'; font-size:8.25pt; color:#000080;">Optional</span><span style=" font-family:'monospace'; font-size:8.25pt;"> </span><span style=" font-family:'monospace'; font-size:8.25pt; color:#000080;">ByVal</span><span style=" font-family:'monospace'; font-size:8.25pt;"> index </span><span style=" font-family:'monospace'; font-size:8.25pt; color:#000080;">As</span><span style=" font-family:'monospace'; font-size:8.25pt;"> </span><span style=" font-family:'monospace'; font-size:8.25pt; color:#000080;">Long</span><span style=" font-family:'monospace'; font-size:8.25pt;">)</span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; font-size:8.25pt;">    </span><span style=" font-family:'monospace'; font-size:8.25pt; color:#008000;">' макрос сохраняет текст из переменной txt в текстовый файл</span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; font-size:8.25pt;">    </span><span style=" font-family:'monospace'; font-size:8.25pt; color:#008000;">' (файл создаётся в папке для временных файлов, получает имя типа text####.txt,</span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; font-size:8.25pt;">    </span><span style=" font-family:'monospace'; font-size:8.25pt; color:#008000;">' где #### - число, заданное через параметр index, или случайное 10-значное)</span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; font-size:8.25pt;">    </span><span style=" font-family:'monospace'; font-size:8.25pt; color:#008000;">' После создания текстового файла он открывается в программе по-умолчанию (например, в Блокноте)</span></p>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'monospace'; font-size:8.25pt; color:#008000;"><br /></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; font-size:8.25pt;">    </span><span style=" font-family:'monospace'; font-size:8.25pt; color:#000080;">On</span><span style=" font-family:'monospace'; font-size:8.25pt;"> </span><span style=" font-family:'monospace'; font-size:8.25pt; color:#000080;">Error</span><span style=" font-family:'monospace'; font-size:8.25pt;"> </span><span style=" font-family:'monospace'; font-size:8.25pt; color:#000080;">Resume</span><span style=" font-family:'monospace'; font-size:8.25pt;"> </span><span style=" font-family:'monospace'; font-size:8.25pt; color:#000080;">Next</span><span style=" font-family:'monospace'; font-size:8.25pt;">: Err.Clear</span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; font-size:8.25pt;">    </span><span style=" font-family:'monospace'; font-size:8.25pt; color:#008000;">' формируем имя для временного файла</span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; font-size:8.25pt;">    filename$ = Environ(</span><span style=" font-family:'monospace'; font-size:8.25pt; color:#800000;">&quot;TEMP&quot;</span><span style=" font-family:'monospace'; font-size:8.25pt;">) &amp; </span><span style=" font-family:'monospace'; font-size:8.25pt; color:#800000;">&quot;\text&quot;</span><span style=" font-family:'monospace'; font-size:8.25pt;"> &amp; IIf(index, index, Left(Rnd() * 1E+15, 10)) &amp; </span><span style=" font-family:'monospace'; font-size:8.25pt; color:#800000;">&quot;.txt&quot;</span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; font-size:8.25pt;">    </span><span style=" font-family:'monospace'; font-size:8.25pt; color:#008000;">' сохраняем текст в файл</span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; font-size:8.25pt;">    </span><span style=" font-family:'monospace'; font-size:8.25pt; color:#000080;">With</span><span style=" font-family:'monospace'; font-size:8.25pt;"> CreateObject(</span><span style=" font-family:'monospace'; font-size:8.25pt; color:#800000;">&quot;scripting.filesystemobject&quot;</span><span style=" font-family:'monospace'; font-size:8.25pt;">).CreateTextFile(filename, </span><span style=" font-family:'monospace'; font-size:8.25pt; color:#000080;">True</span><span style=" font-family:'monospace'; font-size:8.25pt;">)</span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; font-size:8.25pt;">        .Write txt: .</span><span style=" font-family:'monospace'; font-size:8.25pt; color:#000080;">Close</span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; font-size:8.25pt;">    </span><span style=" font-family:'monospace'; font-size:8.25pt; color:#000080;">End</span><span style=" font-family:'monospace'; font-size:8.25pt;"> </span><span style=" font-family:'monospace'; font-size:8.25pt; color:#000080;">With</span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; font-size:8.25pt;">    </span><span style=" font-family:'monospace'; font-size:8.25pt; color:#008000;">' открываем созданный файл</span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; font-size:8.25pt;">    CreateObject(</span><span style=" font-family:'monospace'; font-size:8.25pt; color:#800000;">&quot;wscript.shell&quot;</span><span style=" font-family:'monospace'; font-size:8.25pt;">).Run </span><span style=" font-family:'monospace'; font-size:8.25pt; color:#800000;">&quot;&quot;&quot;&quot;</span><span style=" font-family:'monospace'; font-size:8.25pt;"> &amp; filename$ &amp; </span><span style=" font-family:'monospace'; font-size:8.25pt; color:#800000;">&quot;&quot;&quot;&quot;</span></p>
<p style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; font-size:8.25pt; color:#000080;">End</span><span style=" font-family:'monospace'; font-size:8.25pt;"> </span><span style=" font-family:'monospace'; font-size:8.25pt; color:#000080;">Sub</span></p>
<p style=" margin-top:14px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8.25pt; font-weight:600;">Результат отображения нескольких текстовых переменных в редакторе Notepad++</span></p>
<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><img src="image16865.png" /><span style=" font-size:8.25pt;"> </span></p>
<ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"><li style=" font-size:8.25pt;" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">7947 просмотров </li></ul></td>
<td></td></tr></table></body></html>